package com.servlet;

import com.entity.Book;
import com.mapper.BookMapper;
import com.util.MybatiesUtil;
import org.apache.ibatis.session.SqlSession;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017/6/15.
 */
@WebServlet("/show.do")
public class Show extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MybatiesUtil mu = new MybatiesUtil();
        SqlSession s =mu.getSession();
        BookMapper bookdao =s.getMapper(BookMapper.class);
        /*List<Book> bs  = bookdao.queryAll();*/
        //根据ID查一个对象
      /* Book bs =bookdao.queryById(4);*/

       /* Map<String,Integer> map = new HashMap<String, Integer>();
        int start  =1;
        int pagesize =2;
        map.put("start",start*pagesize-pagesize);
        map.put("pagesize",pagesize);
              List<Book> bs  = bookdao.page(map);*/

        Map<String,Object> map= new HashMap<String, Object>();

        map.put("name","Java");
        map.put("price",200);
        map.put("id",1);

        bookdao.updateById(map);
        req.setAttribute("book",map);
        s.commit();
        s.close();
        req.getRequestDispatcher("index.jsp").forward(req,resp);


    }
}
